<template>
	<view class="home">
		<swiper class="swiper" indicator-dots autoplay  :interval="3000" :duration="1000" circular>
			<swiper-item class="swiper-item" v-for="item in swiperList" :key="item.goods_id">
				<navigator class="navigation" :url="`/subpkg/goodsdetail/goodsdetail?goods_id=${item.goods_id}`">
				<image class="swiper-image" :src="item.image_src" mode="aspectFill"></image>
				</navigator>
			</swiper-item>
		</swiper>
		<view class="navlist">
			<view class="navitem" v-for="(item,index) in navList" :key="index">
				<image @click="navClickHandler(item)" class="navimage" :src="item.image_src" mode="scaleToFill"></image>
			</view>
		</view>
		<view class="floorList">
			<view class="flooritem" v-for="(item,index) in floorList" :key="index">
				<image class="floortitle" :src="item.floor_title.image_src" mode="widthFix"></image>
				<view class="imagebox">
					<view class="leftbox">
						<navigator :url="item.product_list[0].url">
							<image class="image" :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width+'rpx'}" mode="widthFix"></image>
						</navigator>
					</view>
					<view class="rightbox">
						<navigator  v-for="(img,index) in item.product_list.slice(1,5)" :key="index" :url="img.url">
							<image class="image" :style="{width:img.image_width+'rpx'}"  :src="img.image_src" mode="widthFix"></image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
	</view>
	
</template>

<script>
	export default {
		data() {
			return {
				swiperList:[],
				navList:[],
				floorList:[]
			};
		},
		onLoad() {
			this.getSwiperList();
			this.getnavList();
			this.getFloorList();
		},
		methods:{
			async getSwiperList(){
				let {data:{message,meta}} = await uni.$http.get("/api/public/v1/home/swiperdata");
				if(meta.status == 200){
					this.swiperList = message;
				}else{
					uni.$showReqFailToast();
				}
			},
			async getnavList(){
				let {data:{message,meta}} = await uni.$http.get("/api/public/v1/home/catitems");
				if(meta.status == 200){
					this.navList = message;
				}else{
					uni.$showReqFailToast();
				}
			},
			async getFloorList(){
				let {data:{message,meta}} = await uni.$http.get("/api/public/v1/home/floordata");
				if(meta.status == 200){
					//product_list navigator_url  
					message.forEach(floor => {
						floor.product_list.forEach(item => {
							item.url = "/subpkg/goods_list/goods_list?query="+item.navigator_url.split("=")[1]; 
						})
					})
					this.floorList = message;
				}else{
					uni.$showReqFailToast();
				}
			},
			navClickHandler({name}){
				if(name == "分类"){
					uni.switchTab({
						url:"/pages/cate/cate"
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
.home{
	.swiper{
		height: 350rpx;
		width: 100%;
		.navigation,.swiper-item,.swiper-image{
			width: 100%;
			height: 100%;
		}
	}
	.navlist{
		width: 100%;
		display: flex;
		justify-content: space-around;
		margin: 15rpx 0rpx;
		.navitem{
			width: 150rpx;
			height: 165rpx;
			.navimage{
				width: 100%;
				height: 100%;
			}
		}
	}
	.floorList{
		margin-top: 30rpx;
		.flooritem{
			margin-bottom: 30rpx;
			clear: both;
			.floortitle{
				width: 100%;
			}
			.imagebox{
				display: flex;
				justify-content: space-between;
				width: 730rpx;
				margin:0rpx 12rpx;
				.leftbox{
					
				}
				.rightbox{
					margin-left: 18rpx;
					display: flex;
					flex-flow: row wrap;
					align-items:flex-start;
					justify-content:space-between;
				}
			}
		}
	}
}
</style>
